using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Quanlyhocsinh.HeThongLuuTru;
using quanlynhasach.HeThongXuLy;

namespace quanlynhasach.HeThongLuuTru
{
    class SachDAO
    {
        static public DataTable SelectSachLikeName(SachDTO s)
        {
            string sql = "select * from SACH where TenSach like '%" + s.TenSach + "%'";
            return DataAccess.ExcuQuery(sql);
        }
        static public DataTable SelectSachAll()
        {
            string sql = "select* from SACH";
            DataTable dt = DataAccess.ExcuQuery(sql);
            return dt;
        }
        static public void Insert(SachDTO s)
        {
            string sql = "insert into SACH(TenSach,TacGia,MaTheLoai,GiaBan,SoLuongTon) values('" + s.TenSach + "','" + s.TacGia + "'," + s.MaTheLoai + "," + s.GiaBan + "," + s.SoLuongTon + ")";
            DataAccess.ExcuNonQuery(sql);
           
        }
        static public void Update(SachDTO s)
        {
            string sql = "update into SACH(TenSach,TacGia,MaTheLoai,GiaBan,SoLuongTon,) values('" + s.TenSach + "','" + s.TacGia + "'," + s.MaTheLoai + "," + s.GiaBan + "," + s.SoLuongTon + ")";
            DataAccess.ExcuNonQuery(sql);
        }
        static public SachDTO SelectTLByName(string name)
        {
            string sql = "select * from SACH where TenSach='" + name + "'";
            DataTable dt = DataAccess.ExcuQuery(sql);
            if (dt.Rows.Count == 0)
            {
                return null;
            }
            else 
            {
                SachDTO s = new SachDTO();
                s.TenSach = dt.Rows[0].ItemArray[0].ToString();
                return s;
            }
        }
        public static DataTable GetSachCondition(int SoLuongTon)
        {
            string sql = "select * from SACH where SoLuongTon < " + SoLuongTon;
            return DataAccess.ExcuQuery(sql);
        }
    }
}
